function [color_img alpha] = drawColorModel(file_name, gray_image);
gray_image = im2double(gray_image);
%gray_image = (imread('../results/tree_01/itrEM5/cluster_1/tan_129_1/canonical_31.shape.png'));
gray_image = im2double(gray_image);
%file_name = '../results/tree_01/itrEM5/cluster_1/tan_129_1/color_model.color';
p_file = fopen(file_name,'r');
if ~p_file
    disp(['warning, cannot open color model file, ' file_name])
    return;
end
color_model = [];
%%read file%
text = fgetl(p_file);
data= sscanf(text,'%f, ');
width = data(1); height = data(2);

L = zeros(height,width);
A = zeros(height,width);
B = zeros(height,width);
alpha = zeros(height,width);
while(~feof(p_file))
    text = fgetl(p_file);
    data = sscanf(text,'%f, ');
    switch data(1)
        case 0
            color_model=[color_model;data(2:end)'];
        otherwise
            frpintf('unkonw color model type found!\n');
    end
end
fclose(p_file);
%%generate lab image%

n_pt = size(color_model,1);
for i_pt = 1:n_pt
    row = round(color_model(i_pt,1)+randi([-3 3],1));
    col = round(color_model(i_pt,2)+randi([-3 3],1));
    Mu = color_model(i_pt,3:5);
	data = color_model(i_pt,:);
    %Sigma = [data(5) data(7); data(7) data(6)];
    %R = chol(Sigma);
    %z = Mu+randn(1,2)*R;
	z = Mu;
						 
    if( row-8<=0|| row+8>height || col-8<=0 || col+8>width) 
        continue;
    end
    r = 4;
    L(row-r:row+r, col-r:col+r)= z(3);
    A(row-r:row+r, col-r:col+r)= z(1); 
    B(row-r:row+r, col-r:col+r)= z(2);
    alpha(row-r:row+r, col-r:col+r) = 1;
end

%{
n_pt = size(color_model,1);
for i_pt = 1:n_pt
    row = round(color_model(i_pt,1)+randi([-3 3],1));
    col = round(color_model(i_pt,2)+randi([-3 3],1));
    Mu = color_model(i_pt,3:5);
    data = color_model(i_pt,:);
    %Sigma = diag(data(6:8));
    %R = chol(Sigma);
    %z = Mu+randn(1,3)*R;
    z = Mu;
	r = 3;
    if( row-8<=0|| row+8>height || col-8<=0 || col+8>width) 
        continue;
    end
    L(row-r:row+r, col-r:col+r)= z(1);
    A(row-r:row+r, col-r:col+r)= z(2); 
    B(row-r:row+r, col-r:col+r)= z(3);
    alpha(row-r:row+r, col-r:col+r) = 1;
end
%}


%%convert to rgb image, and merge with gray_image
img= zeros(height,width,3);
img(:,:,1) = L; img(:,:,2)=A; img(:,:,3)= B;
%img(:,:,1) = A; img(:,:,2)=B; img(:,:,3)= L;

%cc = makecform('lab2srgb');
%rgb_img = applycform(img,cc);
rgb_img = img;
%rgb_img = img;
for i_ch = 1:3
    layer = rgb_img(:,:,i_ch);
    layer(~alpha)=1;
    rgb_img(:,:,i_ch)=layer;
end
color_img =rgb_img;

for i_ch= 1:3
    color_img(:,:,i_ch) = min(gray_image,rgb_img(:,:,i_ch));
end

ind = (gray_image<0.4);
alpha(ind) =1;
%alpha = double(1-alpha);
